package com.kaifamiao.www.demo.do0906;

import java.sql.*;

public class Demo {
    public static void main(String[] args) {
        Connection connection = null;
        CallableStatement callableStatement = null;
        try {
            //注册驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/kfm";
            //建立连接
             connection= DriverManager.getConnection(url,"root","");
            //创建statement 语句
            callableStatement = connection.prepareCall("{call proc_adder(?,?,?)}");
            //给占位符赋值
            callableStatement.setObject(1,156);
            callableStatement.setObject(2,666);
            //将第三个占位符注册为OUT 类型的整形参数
           callableStatement.registerOutParameter(3,Types.INTEGER);
            //执行存储过程
            callableStatement.executeUpdate();
            //获取第三个类型的参数
            int sum = callableStatement.getInt(3);
            System.out.println("sum = " + sum);

            //关闭连接
            callableStatement.close();
            connection.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
